package com.scm.java.net.sup.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import net.sf.json.util.JSONUtils;

import org.apache.commons.collections.map.HashedMap;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
import com.scm.entity.base.Emp;
import com.scm.entity.base.StoPerformance;
import com.scm.entity.base.StoSalary;
import com.scm.java.net.system.action.BasicAction;
import com.scm.java.net.utils.StringUtils;
/**
 * 工资管理Action
 * @author Administrator
 *
 */
public class SalaryAction extends BasicAction implements ModelDriven<StoSalary>,Preparable{
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private StoSalary salary;
    private List<Emp> emps;
    private String pempId;
	@SuppressWarnings("unchecked")
	public String list() throws Exception{
    	emps=dao.queryList("emp.getEmp", null);
        paginatedQuery("drugStock.getSalary");
    	return "list";
    }
    @SuppressWarnings("unchecked")
	public String toAdd() throws Exception{
    	emps=dao.queryList("emp.getEmp", null);
    	return "addPage";
    }
    public String add() throws Exception{
    	salary.setId(StringUtils.uniqueKey());
    	dao.addObj("drugStock.addSalary",salary);
    	return "succ";
    }
    @SuppressWarnings("unchecked")
	public String toEdit() throws Exception{
    	emps=dao.queryList("emp.getEmp", null);
    	Map paraMap=new HashMap();
    	paraMap.put("salary", salary);
    	salary=(StoSalary) dao.queryList("drugStock.getSalary", paraMap).get(0);
    	return "editPage";
    }
    public String edit() throws Exception{
    	dao.editObj("drugStock.editSalary", salary);
    	return "succ";
    }
    public String del() throws Exception{
    	dao.del("drugStock.delSalary", salary);
    	return "succ";
    }
    //查询某职位的考核指标
    public void getPerformance() throws Exception{
    	Map paraMap=new HashedMap();
    	paraMap.put("empId", pempId);
    	String roleId=(String) dao.queryObject("drugStock.getRoleIdByEmp", paraMap);
    	StoPerformance performance=new StoPerformance();
    	performance.setRoleId(roleId);
    	paraMap.clear();
    	paraMap.put("performance", performance);
    	List<StoPerformance> pers=dao.queryList("drugStock.getPerformances", paraMap);
    	response.setHeader("content-type", "text/html;charset=UTF-8");
    	PrintWriter out=response.getWriter();
    	if(pers.size()>0&&pers!=null){
    		out.write(JSONObject.fromObject(pers.get(0)).toString());
    	}else{
    		out.write("error");
    	}
    }
    public String getPempId() {
		return pempId;
	}
	public void setPempId(String pempId) {
		this.pempId = pempId;
	}
	public List<Emp> getEmps() {
		return emps;
	}
	public void setEmps(List<Emp> emps) {
		this.emps = emps;
	}
	public StoSalary getSalary() {
		return salary;
	}
	public void setSalary(StoSalary salary) {
		this.salary = salary;
	}
	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		salary=new StoSalary();
	}
	@Override
	public StoSalary getModel() {
		// TODO Auto-generated method stub
		return salary;
	}
}
